package com.aaa.ssm.controller;

import com.aaa.ssm.entity.Patient;
import com.aaa.ssm.entity.SysUser;
import com.aaa.ssm.service.PatientService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("patient")
public class PatientController extends BaseController{
    @Resource
    private PatientService patientService;

    @GetMapping("login")
    @ResponseBody
    public Result login(String userName, String password, HttpSession session){
        Patient patient = patientService.checkUser(userName, password);
        if (patient!=null){
            session.setAttribute("userInfo",patient);
        }
        return success(patient);
    }


    @PostMapping("queryByPage")
    @ResponseBody
    public Result queryByPage(@RequestBody Page<Patient> page){
        return success(patientService.queryByPage(page));
    }
    @GetMapping("queryByParam")
    public Result queryByParam(@RequestBody Patient patient){
        List<Patient> patientList=patientService.queryByParam(patient);
        System.out.println(patientList);
        return success(patientList);
    }
    @GetMapping("queryById")
    public Result queryById(int id){
        return success(patientService.queryById(id));
    }
    @PutMapping("add")
    private Result add(@RequestBody Patient patient){
        return success(patientService.add(patient));
    }
    @PutMapping("update")
//    @ResponseBody
    private Result update(@RequestBody Patient patient){
        return success(patientService.update(patient));
    }

    @DeleteMapping("delete")
//    @ResponseBody
    private Result delete(int id){

        return  success(patientService.delete(id));
    }
}
